const fs = require('fs');
const path = require('path');

module.exports = async ctx => {
    try {
        const body = { ...ctx.request.body, time: new Date().getTime() };
        const ldteprojectpath = ctx.request.req.headers.ldteprojectpath;
        const file = path.resolve(ldteprojectpath, './ldte.json');
        fs.writeFileSync(file, JSON.stringify(body, null, 4), { encoding: 'utf8' });
        ctx.status = 200;
    } catch (error) {
        ctx.status = error.code || 500;
        ctx.body = error;
    }
}